<?php
/********************************************************
 *
 * 此文件的作用:
 *		公告表的入口
 *
 * @copyright Copyright (c) 2008-2009
 * @author 刘昌功 lcg635@126.com
 *
 ********************************************************/
defined('APP_DIR') or die('404 Not Found');

FLEA::loadClass('FLEA_Com_RBAC_UsersManager');
FLEA::loadClass('Common_Table');

class Table_Admin extends FLEA_Com_RBAC_UsersManager {
    var $tableName = 'admins';
    var $primaryKey = 'admin_id';
	var $rolesFields = 'roles';

	var $functionFields = array(
		'registerIpField' => 'ip',
		'lastLoginField' => null,
		'lastLoginIpField' => 'ip',
		'loginCountField' => 'loginTimes',
		'isLockedField' => null
	);

    var $manyToMany = array(
        array(
			'tableClass' => 'Table_Role',
			'foreignKey'=> 'admin_id',
			'assocForeignKey' => 'role_id',
			'mappingName' => 'roles',
			'joinTable' => 'roles_admins',
			'enabled' => false
		)
	);

	function form($data = null) {
		$this->_ui = FLEA::initWebControls();
		$form = array(
			'admin_id' => $this->_ui->control('Hidden', 'admin_id',
				array(
					'value' => $data['admin_id']
				),
				true
			),
			'username' => $this->_ui->control('Textbox', 'username',
				array(
					'value' => $data['username'],
					'required' => 'true',
					'check' => 'isLength(3,18);',
					'style' => 'width:150px;',
					'maxlength' => 18,
					'showName' => '用户名'
				),
				true
			),
			'password' => $this->_ui->control('Password', 'password',
   				array(
					'required' => 'true',
					'check' => 'isLength(6,18);',
					'style' => 'width:150px;',
					'showName' => '密码',
       		 		'maxlength' => 18
    			),
				true
			),
			'confirmPassword' => $this->_ui->control('Password', 'confirmPassword',
   				array(
					'required' => 'true',
					'check' => 'isLength(6,18);',
					'style' => 'width:150px;',
					'showName' => '确认密码',
       		 		'maxlength' => 18
    			),
				true
			),
			'level' => $this->_ui->control('DropdownList', 'level',
   				array(
					'required' => 'true',
					'selected' => $data['level'],
					'items' => array(
						'普通管理员' => 0,
						'超级管理员' => 1
					)
    			),
				true
			)
		);
		return $form;
	}
}

